/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boundaries;

import controllers.InvitationManager;
import entities.Invitation;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author Alberto, Alessandra
 */
@ManagedBean
@ViewScoped
public class InvitationListBean {
    
    @EJB
    private InvitationManager im;
    
    private ArrayList<Invitation> invitations;
    
    private Invitation selectedinvitation;
    
    public InvitationListBean () {
        this.invitations = new ArrayList<>();
    }

    public Invitation getSelectedinvitation() {
        return selectedinvitation;
    }

    public void setSelectedinvitation(Invitation selectedinvitation) {
        this.selectedinvitation = selectedinvitation;
    }

    public ArrayList<Invitation> getInvitations() {
        return invitations;
    }

    public void setInvitations(ArrayList<Invitation> invitations) {
        this.invitations = invitations;
    }
    
    @PostConstruct
    public void init() {
        im.visualize(im.getNewInvitations());
        this.invitations.addAll(im.getInvitationList());
    }
    
    public void accept () {
        im.accept(selectedinvitation);
    }
    
    public void decline () {
        im.decline(selectedinvitation);
        this.invitations.clear();
        this.invitations.addAll(im.getInvitationList());
    }
    
}
